function nachmias_states_ = gXnachmias_statelist(varargin)
% BSH: I want to use a *single* statelist for all of the tasks used to
% measure the psychometric function near its accelerating shoulder.  These
% are the collaborations with Jacob Nachmias.

% optional arguments to make statelist somewhat polymorphic
if ~nargin
    lcon = {};
else
    lcon = varargin{1};
end
if nargin < 2
    rcon = {};
else
    rcon = varargin{2};
end
if nargin < 3
    bcon = {};
else
    bcon = varargin{3};
end
if nargin < 4
    ptrs = {};
else
    ptrs = varargin{4};
end
if nargin < 5
    nofp = {{} 'dXtarget'};
else
    nofp = varargin{5};
end
if nargin < 6
    show = 200;
else
    show = varargin{6};
end

post = 6e7;
hang = 50;

noTouch = { ...
    'dXkbHID',  {'any', 'error'}; ...
    'dXlpHID',  {'any', 'error'}; ...
    'dXasl',    {-1, 'error'}};

respond = { ...
    'dXkbHID', {'j', 'right', 'f', 'left'}; ...
    'dXlpHID', {'r2on', 'right', 'l2on', 'left'}};

left = { ...
    'dXkbHID', {'j', 'both'}; ...
    'dXlpHID', {'r2on', 'both'}};

right = { ...
    'dXkbHID', {'f', 'both'}; ...
    'dXlpHID', {'l2on', 'both'}};

rP = @rPlay;
rH = @rGraphicsShow;
rU = @rVarUpdate;
rC = @rCallFunction;
nxt = 'next';
err = 'error';
tg = 'dXtarget';
bp = 'dXbeep';

% THE STATE DINNER. Careful -- this MUST be a double cellery.
%
%   You know those guitars that are like *double* guitars?
%
%   name        fun args        jump    wait    repsDrawQuery   cond
arg_dXstate = {{ ...
    'clear',	{}, {},         nxt,    0,      0,  5,  noTouch,{}; ...
    'indicate', rH, {tg},       nxt,    0,      0,  3,  1,      {}; ...
    'tone1',	rP, {bp, 1},    nxt,    100,	0,  0,  1,      {}; ...
    'nextStim',	rU, ptrs,       nxt,    300,    0,  0,  1,      {}; ...
    'undrawFP',	rH, nofp,       nxt,    250,	0,  0,  1,      {}; ...
    'tone2',	rP, {bp, 1},    nxt,    100,	0,  0,  1,      {}; ...
    'hideFP',	{}, {},         nxt,    0,      0,  3,  1,      {}; ...
    'waitStim',	rC, {1},        nxt,    50,     0,  0,  1,      {}; ...
    'showStim', {}, {},         nxt,    show,   0,  1,  1,      {}; ...
    'hideStim', {}, {},         nxt,    0,      0,  5,  1,      {}; ...
    ...
    'respond',  {}, {},         err,    post,   0,  0,  respond,{}; ...
    'left',     {}, {},         err,    hang,	0,  0,  left,   lcon; ...
    'right',    {}, {},         err,    hang,	0,  0,  right,  rcon; ...
    'both',     {}, {},         err,    0,      0,  0,  0,      bcon; ...
    ...
    'correct',  rP, {bp, 2},	'end',  500,    0,  0,  0,      {}; ...
    'incorrect',rP, {bp, 3},    'end',  250,    1,  0,  0,      {}; ...
    'abstain',  rP, {bp, 4},    nxt,	400,    0,  0,  0,      {}; ...
    'absBeep',  rP, {bp, 1},    'end',  100,    0,  0,  0,      {}; ...
    'error',    {}, {},         nxt,    0,      0,  5,  0,      {}; ...
    'errBeep',	rP, {bp, 1},    'end',	100,    4,  0,  0,      {}; ...
    'end',      {}, {},         'x',    0,      0,  0,  0,      {}; ...
    }};
sz = size(arg_dXstate{1}, 1);

tony = {'current', false, true, false};
nachmias_states_ = {'dXstate', sz, tony, arg_dXstate};